package jiachunlei.observer.lesson2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 使用java自带的观察者方法
 *
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/12/6 22:29
 * @see java.util.Observable
 * @see java.util.Observer
 */
public class ObserverClient2
{
    public static void main(String[] args)
    {
        for (; ; )
        {
            RealSubject subject = new RealSubject();
            RealObserver realObserver = new RealObserver();
            subject.addObserver(realObserver);
            subject.makeChanged(getType());
        }
    }

    private static String getType()
    {
        try
        {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("请输入文字：");
            String line = reader.readLine();
            return line;
        } catch (IOException e)
        {
            e.printStackTrace();
            return "";
        }
    }
}
